<template>
	<view class="content" :style="{background: `url(${imgPath}storage/home/home_bg.png)`,backgroundSize: '100%'}">
		<view class="box">
			<view class="search">
				<u--input placeholder="点击搜索寺庙" prefixIcon="search" prefixIconStyle="font-size: 44rpx;color: #111" border="none"
					v-model="name"></u--input>
				<view class="searchbtn" @click="search">
					搜索
				</view>
			</view>
			<scroll-view class="templelist" scroll-y @scrolltolower="getTempleList">
				<view class="item" v-for="item in templelist" @click="selectTemple(item)">
					<view class="title">
						{{item.name}}
					</view>
					<view class="address">
						<uni-icons type="location" size="15"></uni-icons>
						<text>{{item.address}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				paging: {
					page: 1,
					limit: 10,
				},
				total: null,
				templelist: [],
				name: ''
			}
		},
		onLoad() {
			this.getTempleList()
		},
		onPullDownRefresh() {
			this.search()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			getTempleList() {
				if (this.total == this.templelist.length) return
				this.$api.templelist({
					...this.paging,
					name: this.name
				}).then(res => {
					console.log(res);
					this.templelist = [...this.templelist, ...res.data.list]
					this.paging.page++
					this.total = res.data.total
				})
			},
			search() {
				this.total = null
				this.paging.page = 1
				this.templelist = []
				this.getTempleList()
			},
			selectTemple(obj) {
				let pages = getCurrentPages()
				let prevPage = pages[pages.length - 2]
				prevPage.$vm.selectTemple({
					id: obj.temple_id,
					name: obj.name
				})
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		min-height: 100vh;
		z-index: -1;
	}

	.box {
		padding: 20rpx 30rpx 0;
	}

	.search {
		padding: 0 10rpx 0 30rpx;
		height: 104rpx;
		background: #FEF1DC;
		border-radius: 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;

		.searchbtn {
			margin-left: 10rpx;
			width: 170rpx;
			height: 84rpx;
			background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
			border-radius: 20rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 84rpx;
			text-align: center;
			font-style: normal;
		}
	}

	.templelist {
		padding-top: 16rpx;
		height: calc(100vh - 150rpx);
	}

	.item {
		height: 148rpx;
		background: #FEF1DC;
		border-radius: 20rpx;
		margin-bottom: 16rpx;
		box-sizing: border-box;
		padding: 36rpx 0 0 30rpx;

		.title {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #111111;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
		}

		.address {
			padding-top: 10rpx;
			display: flex;

			text {
				padding-left: 5rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 22rpx;
				color: #AAAAAA;
				line-height: 45rpx;
				text-align: left;
				font-style: normal;
			}
		}
	}
</style>